/*
|-----------------------------------------------------------------------------|
| Overall ANTLR Grammar File Structure                                        |
|-----------------------------------------------------------------------------|
| «grammarType» grammar name;
|   «optionsSpec»     = options { ... }
|   «tokensSpec»      = tokens { ... }
|   «attributeScopes» = «@action-scope-name::action-name» { ... }
|   «actions»
|   // rules
|   rule1 : ... ;
|   rule2 : ... ;
|   ...
|_____________________________________________________________________________|
|   «grammarType»         = ( lexer | parser | tree | <empty> )
|   «optionsSpec»         = options { ... }
|   «tokensSpec»          = tokens { ... }
|   «attributeScopes»     = 
|   «actions»             = @«action-scope-name»::«action-name» { ... }
|    «action-scope-name» = ( lexer | parser | tree | <empty> = parser )
|    «action-name»       = ( header | members | rulecatch | synpredgate )
|-----------------------------------------------------------------------------|
*/
parser grammar GDLParser;

  options {
	  language = Java;
	  output = AST;
	  tokenVocab = GDLLexer;
  }// options

  @parser::header {
    package pl.p06.antlr3;
  }//header
  @parser::members {
  }// members

//= Grammar Rules GDL ========================================================|
document : graph ;

	graph
	  : Graph Colon LeftBracket
	      (node | edge)*
	    RightBracket
	  ;
	
		node
		  : Node Colon LeftBracket 
		      node_attr
		    RightBracket
		  ;
		
			node_attr
			options { backtrack=true; k = 2; }
			  : title label? borderstyle?
			  | title borderstyle? label?
			  | label title? borderstyle?
			  | label borderstyle? title?
			  | borderstyle? title label?
			  | borderstyle? label title?
			  ;
			  
				title
				  : Title Colon StringLiteral
				  ;
				
				label
				  : Label Colon StringLiteral
				  ;
				
				borderstyle
				  : BorderStyle Colon borderstyle_attr
				  ;
				
					borderstyle_attr
					  : Solid
					  | Dashed
					  | Dotted
					  ;
		
		edge
		  : Edge Colon LeftBracket
		      edge_attr
		    RightBracket
		  ;
		
			edge_attr
			options { backtrack=true; k = 2; }
			  : source target arrowstyle?
			  | source arrowstyle? target
			  | target source arrowstyle?
			  | target arrowstyle? source
			  | arrowstyle? source target
			  | arrowstyle? target source
			  ;
			
				source
				  : Source Colon StringLiteral
				  ;
				
				target
					: Target Colon StringLiteral
					;
				
				arrowstyle
					: ArrowStyle Colon arrowstyle_attr
					;
				
					arrowstyle_attr
					  : Solid
					  | Line
					  | None
					  ;